﻿
using System.Windows.Media.Imaging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

using Puddy.Utils;
using System.Windows;
using System.Runtime.Serialization;


namespace Puddy.ViewModels
{
    [DataContract()]
    public class LocationViewModel : INotifyPropertyChanged
    {
        public LocationViewModel()
        {

        }

        public LocationViewModel(String _name, String _address, int _state)
        {
            Name = _name;
            Address = _address;
            State = _state;
        }


        String name;

        [DataMember(Name = "Name")]
        public String Name
        {
            get { return name.ToUpper(); }
            set {
                if (name != value)
                {
                    name = value;
                    NotifyPropertyChanged("Name");
                }
            }
        }

        String address;

        [DataMember(Name = "Address")]
        public String Address
        {
            get { return address; }
            set {
                if (address != value)
                {
                    address = value;
                    NotifyPropertyChanged("Address");
                }
            }
        }

        private ImageSource _image = null;

        public ImageSource Image
        {
            get
            {
                
                    BitmapImage bmi = null;
                    Uri uri = null;
                    switch (state)
                    {
                        case Constants.ON_STATE: uri = new Uri(@"/Assets/alarm on icon.png", UriKind.Relative);
                            
                            
                            break;
                        case Constants.OFF_STATE: uri = new Uri(@"/Assets/alarm off icon.png", UriKind.Relative);
                            
                            break;
                        case Constants.DELETE_STATE: uri = new Uri(@"/Assets/delete item icon.png", UriKind.Relative);
                            
                            break;
                    }

                    bmi = new BitmapImage(uri);             
                    this._image = bmi;
                    

                    //if (this._image == null)
                    //{
                    //    this._image = new BitmapImage(new Uri("/Assets/Images/img_fakeEbook.png"));
                    //}
                

                return this._image;
            }

            set
            {
                _image = value;
                NotifyPropertyChanged("Image");
            }
        }

        double latitude;

        [DataMember(Name = "Latitude")]
        public double Latitude
        {
            get { return latitude; }
            set { latitude = value; }
        }

        double longitude;

        [DataMember(Name = "Longitude")]
        public double Longitude
        {
            get { return longitude; }
            set { longitude = value; }
        }

        int state;

        [DataMember(Name = "State")]
        public int State
        {
            get { return state; }
            set {
                if (state != value)
                {
                    state = value;
                    NotifyPropertyChanged("Image");
                    NotifyPropertyChanged("ForeColorText");
                    NotifyPropertyChanged("IsShow");
                }
            }
        }

        bool alreadyAlarm = false;

        public bool AlreadyAlarm
        {
            get { return alreadyAlarm; }
            set { alreadyAlarm = value; }
        }

        String foreColorText;

        public String ForeColorText
        {
            get {
                switch (state)
                {
                    case Constants.ON_STATE:
                        foreColorText = "#B8F2F9";
                        break;
                    case Constants.OFF_STATE:
                        foreColorText = "Gray";
                        break;
                    case Constants.DELETE_STATE:
                        foreColorText = "#E60000";
                        break;
                }
                return foreColorText; 
            }
            set { 
                foreColorText = value;
                NotifyPropertyChanged("ForeColorText");
            }
        }

        Visibility isShow;

        public Visibility IsShow
        {
            get {
                if (state == Constants.DELETE_STATE)
                    isShow = Visibility.Visible;
                else
                    isShow = Visibility.Collapsed;
                return isShow;
            }
            set {
                NotifyPropertyChanged("IsShow");
                isShow = value;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
